home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig07_04.jar / Ch07 / Fig07_04 / Emply1.cpp < prev    next >
C/C++ Source or Header  |  1997-10-20  |  1KB  |  46 lines

  1. // Fig. 7.4: emply1.cpp
  2. // Member function definitions for Employee class.
  3. #include <iostream.h>
  4. #include <string.h>
  5. #include "emply1.h"
  6. #include "date1.h"
  7.  
  8. Employee::Employee( char *fname, char *lname,
  9.                     int bmonth, int bday, int byear,
  10.                     int hmonth, int hday, int hyear )
  11.    : birthDate( bmonth, bday, byear ), 
  12.      hireDate( hmonth, hday, hyear )
  13. {
  14.    // copy fname into firstName and be sure that it fits
  15.    int length = strlen( fname );
  16.    length = ( length < 25 ? length : 24 );
  17.    strncpy( firstName, fname, length );
  18.    firstName[ length ] = '\0';
  19.  
  20.    // copy lname into lastName and be sure that it fits
  21.    length = strlen( lname );
  22.    length = ( length < 25 ? length : 24 );
  23.    strncpy( lastName, lname, length );
  24.    lastName[ length ] = '\0';
  25.  
  26.    cout << "Employee object constructor: "
  27.         << firstName << ' ' << lastName << endl;
  28. }
  29.  
  30. void Employee::print() const
  31. {
  32.    cout << lastName << ", " << firstName << "\nHired: ";
  33.    hireDate.print();
  34.    cout << "  Birth date: ";
  35.    birthDate.print();
  36.    cout << endl;
  37. }
  38.  
  39. // Destructor: provided to confirm destruction order
  40. Employee::~Employee()
  41.    cout << "Employee object destructor: " 
  42.         << lastName << ", " << firstName << endl;
  43. }
  44.  
  45.